package com.hk.Mgr.web.controller.app.yingmi;

import com.hk.api.ProcessAPI;
import com.hk.api.exceptions.ValidateException;
import com.hk.app.utils.YingmiOpenAPI;
import com.hk.base.BaseCtrl;
import com.hk.commons.enm.YingmiTransactionType;
import com.hk.commons.entity.sys.SysUser;
import com.hk.commons.vo.JsonResult;
import com.hk.service.sys.ISysUser;
import com.hk.yingmi.YingmiOpenAPIConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Antinomy on 17/8/24.
 */
@Controller
@RequestMapping(value = BaseCtrl.App)
public class YingmiOrderController {

    @Autowired
    private YingmiOpenAPI openAPI;

    @Autowired
    private ISysUser sysUser;

    @RequestMapping(value = YingmiOpenAPIConstant.BROKER_ORDER_NO, method = RequestMethod.GET)
    @ResponseBody
    public JsonResult brokerOrderNo(HttpServletRequest request, Long userId, YingmiTransactionType type) {
        ProcessAPI api = (jsonResult, validate) -> {
            validate.check("userId", userId);
            validate.check("type", type);

            String orderNo = userId
                    + type.getCode()
                    + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddhhmmssSSS"));

            jsonResult.result = orderNo;
        };

        return api.process(request);
    }
}
